import type {
  KnowledgeParams,
  KnowledgePage,
  DoctorPage,
  PageParams,
  FollowType,
  TopDep,
  Image,
  ConsultOrderPreParams,
  ConsultOrderPreData,
  PartailConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage
} from '@/types/consult'
import { request } from '@/utils/request'

// 1. 获取文章分页列表
export const getKnowledgePage = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)

// 2. 获取医生分页列表
export const getDoctorPage = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

// 3. 关注与取消关注
export const followDoctor = (id: string, type: FollowType = 'doc') =>
  request<{ id: string }>('/like', 'POST', { id, type })

// 4. 获取所有的科室
export const getAllDep = () => request<TopDep[]>('/dep/all')

// 5. 上传图片
export const uploadImage = (file: File) => {
  // 5.1 创建formData对象
  const fd = new FormData()
  fd.append('file', file)
  // 5.2 调用函数
  return request<Image>('/upload', 'POST', fd)
}

// 6. 获取预支付信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 7. 生成订单
export const createConsultOrder = (data: PartailConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', data)

// 8. 获取支付跳转的url地址
export const getConsultOrderPayUrl = (data: {
  paymentMethod: number
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)

// 9. 获取问诊订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

// 10. 根据处方id获取处方单
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`)

// 11. 评分(医生)
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

// 12. 获取问诊订单列表
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 13. 取消订单
export const cancelOrder = (id: string) =>
  request(`/patient/order/cancel/${id}`, 'PUT')

// 14. 删除订单
export const deleteOrder = (id: string) =>
  request(`/patient/order/${id}`, 'DELETE')
